<template>
  <view class="header flex flex-x-between fz30 bg-white">
    <view class="flex flex-y-center">
      <sw-icons color="#fb5450" icon="icon-didian" class="mr10"></sw-icons>
      {{ state.networkName }}
    </view>
    <view>营业时间： {{ state.serviceTime }}小时</view>
  </view>
</template>

<script setup>
  import { reactive, getCurrentInstance } from 'vue';
  import { onLoad } from '@dcloudio/uni-app';
  import { queryByMainBoardId } from '@/common/js/getData.js';

  const { proxy } = getCurrentInstance();

  const state = reactive({
    networkName: '',
    serviceTime: ''
  });

  // 获取网点信息
  const getInfo = () => {
    const data = {
      mainboardId: getApp().globalData.mainboardId
    }
    queryByMainBoardId(data).then(res => {
      const { result } = res;
      getApp().globalData.networkName = result.networkName;
      getApp().globalData.serviceTime = result.serviceTime;
      state.networkName = getApp().globalData.networkName;
      state.serviceTime = getApp().globalData.serviceTime;
    });
  };

  // 页面加载完成
  onLoad(async () => {
    await proxy.$onLaunched;
    state.networkName = getApp().globalData.networkName;
    state.serviceTime = getApp().globalData.serviceTime;
    if (!(state.networkName && state.serviceTime)) {
      getInfo();
    }
  });
</script>

<style lang="less" scoped></style>
